<template>
  <div>
    <div class="serviceDetails" v-if="showServices">
      <div class="header">
        <van-icon name="cross" @click="showServices = !showServices" />
      </div>
      <div class="titleInfo">
        <div class="cinemaName">
          {{ cinemaInfo.name }}
        </div>
        <ul>
          <li v-for="item in cinemaInfo.services" :key="item.name">
            <div class="serviceName">
              <van-tag plain type="warning">{{ item.name }} </van-tag>
            </div>
            <div class="introduce">
              {{ item.description }}
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="cinemaInfo" v-if="!showServices">
      <div class="header">
        <van-icon name="arrow-left" @click="goBack()" />
      </div>
      <div class="titleInfo">
        <div class="cinemaName">
          {{ cinemaInfo.name }}
        </div>
        <div class="services" @click="showServices = !showServices">
          <div class="servicesTag">
            <van-tag
              plain
              type="warning"
              v-for="item in cinemaInfo.services"
              :key="item.name"
              >{{ item.name }}</van-tag
            >
            <van-icon name="arrow" />
          </div>
        </div>
      </div>
      <div class="address">
        <p><van-icon name="location-o" @click="showDetails()" /></p>
        <p class="addressInfo">{{ cinemaInfo.address }}</p>
        <p><van-icon name="phone-o" @click="showDetails('phoneNumber')" /></p>
      </div>
      <div class="cinemaSwiper">
        <cinema-swiper :slideNum="films.length">
          <div class="swiper-slide" v-for="item in films" :key="item.filmId">
            <img :src="item.poster" alt="" />
          </div>
        </cinema-swiper>
      </div>
      <div>{{ showTime }}</div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import http from "@/utils/http.js";
import { Tag, Icon } from "vant";
import Vue from "vue";
Vue.use(Tag).use(Icon);
import cinemaSwiper from "./cinemaSwiper.vue";
export default {
  data() {
    return {
      cinemaInfo: {}, // 电影院信息
      showServices: false, // 是否显示电影院服务
      films: [], // 电影院电影列表
      showTime: moment(1632104700).format("yyyy-MM-DD HH:mm:ss"),
    };
  },
  components: { cinemaSwiper },
  methods: {
    getTime() {
      let time = "2021-09-20 10:25:00";
      let date = new Date(time);
      console.log(date.getTime());
      let str = moment(1632104700000).format("yyyy-MM-DD HH:mm:ss");
      console.log(str);
    },
    goBack() {
      this.$router.go(-1);
    },
    showDetails(name) {
      if (name === "phoneNumber") {
        let result = this.cinemaInfo.phone;
        if (!result) {
          for (const i of this.cinemaInfo) {
            result += "/" + i;
          }
        }
        this.$dialog.alert({
          title: "电话号码",
          message: result,
        });
      } else {
        this.$dialog.alert({
          title: "经纬度",
          message: `经度：${this.cinemaInfo.longitude},纬度：${this.cinemaInfo.latitude}`,
        });
      }
    },
  },
  mounted() {
    this.getTime();
    // 获取电影院信息
    http({
      url: `/gateway/?cinemaId=${this.$route.params.id}&k=3037685`,
      headers: {
        "X-Host": "mall.film-ticket.cinema.info",
      },
    }).then((res) => {
      console.log(res);
      this.cinemaInfo = res.data.data.cinema;
    });
    // 获取电影院电影列表
    http({
      url: `/gateway/?cinemaId=${this.$route.params.id}&k=3037685`,
      headers: {
        "X-Host": "mall.film-ticket.film.cinema-show-film",
      },
    }).then((res) => {
      console.log(res);
      this.films = res.data.data.films;
    });
  },
};
</script>
<style lang='scss' scoped>
.serviceDetails {
  .header {
    height: 40px;
    line-height: 40px;
    padding: 4px 10px;
    i {
      font-size: 22px;
    }
  }
  .titleInfo {
    .cinemaName {
      text-align: center;
      color: #191a1b;
      margin-bottom: 10px;
    }
    ul {
      li {
        padding: 14px 12px;
        display: flex;
        .serviceName {
          flex: 1;
        }
        .introduce {
          flex: 5;
          font-size: 14px;
        }
      }
    }
  }
}

.cinemaInfo {
  color: #191a1b;
  .header {
    height: 40px;
    line-height: 40px;
    padding: 4px 10px;
    i {
      font-size: 22px;
    }
  }
  .titleInfo {
    text-align: center;
    .cinemaName {
      margin-bottom: 10px;
    }
    .services {
      .servicesTag {
        position: relative;
        span {
          margin: 0 4px;
        }
        i {
          position: relative;
          top: 3px;
          color: #ff976a;
        }
      }
    }
  }
  .address {
    display: flex;
    justify-content: space-around;
    align-items: center;
    p {
      text-align: center;
      flex: 1;
      i {
        font-size: 22px;
        color: #7d7d7e;
      }
    }
    .addressInfo {
      flex: 5;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
  .cinemaSwiper {
    height: 160px;
    width: 100%;
    background-color: pink;
    .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: #fff;

      /* Center slide text vertically */
      display: -webkit-box;
      display: -ms-flexbox;
      display: -webkit-flex;
      display: flex;
      -webkit-box-pack: center;
      -ms-flex-pack: center;
      -webkit-justify-content: center;
      justify-content: center;
      -webkit-box-align: center;
      -ms-flex-align: center;
      -webkit-align-items: center;
      align-items: center;
      transition: 300ms;
      transform: scale(0.8);
      img {
        height: 160px;
      }
    }
    .swiper-slide-active,
    .swiper-slide-duplicate-active {
      transform: scale(1);
    }
  }
}
</style>